package entity

import (
	"log"

	"github.com/gin-gonic/gin"
)

// app
const (
	APPName = "tone" + "agent"
	APPPort = 8479
	Mode    = gin.ReleaseMode
	Version = "2.0.10"
)

var (
	Debug                 bool
	ResultPath            string
	ScriptPath            string
	ConfigPath            string
	TemplatesPath         string
	LogPath               string
	UpgradeScriptFile     string
	ListVersionScriptFile string
	TaskOutputPath        string
)

func InitPathConst() {
	if Debug {
		log.Println("=====Starting the service in debug mode=====")
		ResultPath = "./.tmp/usr/share/" + APPName + "/results"
		ScriptPath = "./.tmp/usr/share/" + APPName + "/scripts"
		ConfigPath = "./.tmp/etc/" + APPName + "/conf"
		TemplatesPath = "./.tmp/usr/share/" + APPName + "/templates"
		LogPath = "./.tmp/var/log/" + APPName
		TaskOutputPath = "./.tmp/usr/share/" + APPName + "/task_output"
	} else {
		ResultPath = "/usr/share/" + APPName + "/results"
		ScriptPath = "/usr/share/" + APPName + "/scripts"
		ConfigPath = "/etc/" + APPName + "/conf"
		TemplatesPath = "/usr/share/" + APPName + "/templates"
		LogPath = "/var/log/" + APPName
		TaskOutputPath = "/usr/share/" + APPName + "/task_output"
	}
	UpgradeScriptFile = "/tmp/toneagent_upgrade.sh"
	ListVersionScriptFile = "/tmp/toneagent_list_version.sh"
}

// log
const (
	LogRotationTm   = 24  // 每天分割一个日志文件
	LogMaxSize      = 100 // 单个log文件最大值
	LogMaxAge       = 7   // 最长保存 7 天的日志
	LogMaxBackups   = 10  // 最长保存 10个 的备份日志
	LogLevel        = "info"
	PrettyPrint     = false
	TimestampFormat = "2006-01-02 15:04:05"
)

// task status
const (
	TaskRunningStatus   = "running"
	TaskCompletedStatus = "completed"
)

// mode
const (
	ActiveMode  = "active"
	PassiveMode = "passive"
)

// api
const (
	HeartbeatAPI  = "api/agent/heartbeat"
	PullTaskAPI   = "api/agent/pull_task"
	SyncResultAPI = "api/agent/result_sync"
)

// response
const (
	ResponseOk   = "ok"
	ResponseFail = "fail"
)

// config
const (
	ModeConfigKey             = "mode"
	TSNConfigKey              = "tsn"
	ProxyConfigKey            = "proxy"
	AllowModifyThroughPageKey = "allows-modify-through-page"
	AuthPassword              = "auth-password"
	HttpProxy                 = "http-proxy"
	ConfigType                = "yaml"
	HeartbeatIntervalKey      = "heartbeat-interval"
	PullTaskIntervalKey       = "pull-task-interval"
	SyncResultIntervalKey     = "sync-result-interval"
	CheckProcessIntervalKey   = "check-process-interval"
)

// default cron interval
const (
	//DefaultHeartbeatInterval        = "*/5 * * * * *" // 每5s
	//DefaultPullTaskInterval         = "*/3 * * * * *" // 每3s
	//DefaultSyncResultInterval       = "*/3 * * * * *" // 每2s
	//DefaultCheckTaskProcessInterval = "0 1 * * * *"   // 整点
	DefaultHeartbeatInterval        = 5
	DefaultPullTaskInterval         = 3
	DefaultSyncResultInterval       = 3
	DefaultCheckTaskProcessInterval = 3600
)

const Prompts = `
┌───────────────────────────────────────────────────────────────────────┐
│                         ToneAgent Service                             │
├──────────────────────┬────────────────────────────────────────────────┤
│     ▄██ ████ ██▄     │  Name   :  tone-agent   	    	   	│
│          ██          │  Version:  %s 		   	        │
│          ██          │  Vendor :  T-ONE			        │
│          ██          │  Gitee  :  https://gitee.com/anolis/tone-agent │
└──────────────────────┴────────────────────────────────────────────────┘
`

const HelpDoc = `
-----------------------------------------------------------
*文件
   >配置文件：/etc/toneagent/conf/toneagent.yaml
   >日志文件：/var/log/toneagent/toneagent.log
*服务
   >查看服务：systemctl status toneagent
   >重启服务：systemctl restart toneagent
*帮助
   >查看帮助：toneagent -h
*心跳
   >同步心跳测试：toneagent -test
*版本
   >查看当前版本：toneagent -v
   >查看可用版本：toneagent -l
*升级
   >升级到最新版本：toneagent -upgrade=latest
   >升级到稳定版本：toneagent -upgrade=stable
   >升级到指定版本：toneagent -upgrade=2.0.x
*配置
   >更改[tsn]配置：toneagent -set-tsn=xxx
   >更改[mode]配置：toneagent -set-mode=active
   >更改[proxy]配置：toneagent -set-proxy=https://proxy1.cn
-----------------------------------------------------------
`
